/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.h2database;

import com.j256.ormlite.dao.Dao;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author asus
 */
public class StudentService {
    
    private Dao<StudentInfo,Integer> stuDao;
    
    public StudentService(Dao<StudentInfo,Integer> stuDao){
        this.stuDao= stuDao;
    }
    /**
     * 新增，修改。
     * @param stu 
     */
    public void update(StudentInfo stu){
        try {
            stuDao.update(stu);
        } catch (SQLException ex) {
            Logger.getLogger(StudentService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void save(StudentInfo stu){
        try {
            stuDao.create(stu);
        } catch (SQLException ex) {
            Logger.getLogger(StudentService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    // 删除 根据条件
    public void del(StudentInfo stu){
        try {
            stuDao.delete(stu);
        } catch (SQLException ex) {
            Logger.getLogger(StudentService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    // 根据主键删除
    public void delById(Integer id){
        try {
            stuDao.deleteById(id);
        } catch (SQLException ex) {
            Logger.getLogger(StudentService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    //显示所有的记录信息
    public List<StudentInfo> queryAll(){
        try {
            return stuDao.queryForAll();
        } catch (SQLException ex) {
            Logger.getLogger(StudentService.class.getName()).log(Level.SEVERE, null, ex);
        }
        return new ArrayList<StudentInfo>();
    }
    
}
